
import React, { useState } from 'react';
import { Form, Button, Input, Modal } from 'antd';
import PartQuick from '@/pages/part/partQuick';

export interface SelectProps {
    width?: number,
    cRef?: any,
    name?: any,
    label?: string,
    required?: boolean,
    placeholder?: string,
    noStyle?: boolean,
    setCurrent: (item: any) => void,
    pType?:string
}
const PartSelect: React.FC<SelectProps> = (props: SelectProps) => {
    const [visible, setVisible] = useState<boolean>(false);
    const switchModal = () => {
        setVisible(!visible)
    }
    const setCurrent = (item: any) => {
        props.setCurrent(item)
        switchModal()
    }
    return (
        <>
            <Form.Item
                noStyle={props.noStyle}
                name={props.name}
                rules={[{ required: props.required, message: (props.label ? props.label : props.placeholder) + "必填" }]}>
                <Input style={{ width: props.width }} />
            </Form.Item>
            <Form.Item noStyle={props.noStyle}>
                <Button type="primary" onClick={switchModal}>选择</Button>
            </Form.Item>
            <Modal
                title="物料选择"
                visible={visible}
                destroyOnClose={true}
                onCancel={switchModal}
                footer={false}
            >
                <PartQuick pType={props.pType} setPart={(item: any) => setCurrent(item)} />
            </Modal>
        </>
    )
}
export default PartSelect;